package com.gcxx.goods.sys.service.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gcxx.framework.base.entity.PageBean;
import com.gcxx.framework.base.service.BaseService;
import com.gcxx.framework.util.string.StringUtil;
import com.gcxx.goods.sys.dao.IGoodsSysTypeDAO;
import com.gcxx.goods.sys.entity.GoodsSysType;
import com.gcxx.goods.sys.service.IGoodsSysTypeService;

/**
 * <strong>Title : GoodsSysTypeServiceImpl<br></strong>
 * <strong>Description : </strong>GoodsSysTypeServiceImpl接口实现类<br> 
 * <strong>Create on : 2015-06-01<br></strong>
 * <p>
 * <strong>Copyright (C) 天津共创鑫星科技有限公司_智能链管理系统<br></strong>
 * <p>
 * @author guoyi<br>
 * @version <strong>1.0</strong><br>
 * <br>
 * <strong>修改历史:</strong><br>
 * 修改人		修改日期		修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */
public class GoodsSysTypeServiceImpl extends BaseService implements IGoodsSysTypeService{
	
	private static final Log log = LogFactory.getLog(GoodsSysTypeServiceImpl.class);

	private IGoodsSysTypeDAO goodsSysTypeDAO;
	
	public void setGoodsSysTypeDAO(IGoodsSysTypeDAO goodsSysTypeDAO) {
		this.goodsSysTypeDAO = goodsSysTypeDAO;
	}
	public IGoodsSysTypeDAO getGoodsSysTypeDAO() {
		return this.goodsSysTypeDAO;
	}
	
	public void delete(List<String> idList) {
		try {
			if(idList != null && !idList.isEmpty()){
				goodsSysTypeDAO.delete(idList);
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
			throw e;
		}
		
	}

	public List getAll() {
		return goodsSysTypeDAO.findAll();
	}
	
	public List<GoodsSysType> getByProperty(String propertyName, Object value){
		if(StringUtil.isNotNull(propertyName)){
			return goodsSysTypeDAO.findByProperty(propertyName, value);
		}
		return null;
	}

	public GoodsSysType getById(String id) {
		if(StringUtil.isNotNull(id)){
			return goodsSysTypeDAO.findById(id);
		}
		return null;
	}

	public void save(GoodsSysType goodsSysType) {
		if(goodsSysType != null){
			goodsSysType.setId(getID("GST"));
			goodsSysTypeDAO.save(goodsSysType);
		}
	}

	public void update(Map<String, String> map) {
		if(map != null && !map.isEmpty()){
			goodsSysTypeDAO.update(map);
		}
	}
	
	public PageBean getByCondition(PageBean page){
		return goodsSysTypeDAO.findByCondition(page);
	}
	
	
	/* (non-Javadoc)
	 * @see com.gcxx.goods.sys.service.IGoodsSysTypeService#getAllGoodsTypeMap(java.lang.String)
	 */
	@Override
	public Map<String,GoodsSysType> getAllGoodsTypeMap(Map<String, String> condition) {
		Map<String,GoodsSysType> map =null;
		try {
			List<GoodsSysType> list= goodsSysTypeDAO.getEntitysByGoodsType(condition);
			if(list != null && ! list.isEmpty()){
				map = new HashMap<String, GoodsSysType>();
				for (GoodsSysType goodsSysType : list) {
					map.put(goodsSysType.getId(), goodsSysType);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}
	@Override
	public void saveOrUpdate(GoodsSysType goodsSysType) {
		try {
			if(StringUtil.isNull(goodsSysType.getId())){
				goodsSysType.setId(getID("GST"));
			}
			goodsSysTypeDAO.saveOrUpdate(goodsSysType);
		} catch (RuntimeException e) {
			e.printStackTrace();
			throw e;
		}
	}
	/* (non-Javadoc)
	 * @see com.gcxx.goods.sys.service.IGoodsSysTypeService#checkGoodsTypeNoRepeat(java.lang.String, java.lang.String)
	 */
	@Override
	public boolean checkGoodsTypeNoCanUse(String id, String goodsTypeNo) {
		return goodsSysTypeDAO.checkGoodsTypeNoCanUse(id,goodsTypeNo);
	}
	
	@Override
	public List<GoodsSysType> getAllGoodsType(Map<String, String> condition) {
		List<GoodsSysType> list =null;
		try {
			list= goodsSysTypeDAO.getEntitysByGoodsType(condition);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
